{% extends 'base.html' %}
{% load buttons %}
{% load custom_links %}
{% load helpers %}
{% load plugins %}

{% block title %}{{ object.manufacturer }} {{ object.model }}{% endblock %}

{% block header %}
    <div class="row noprint">
        <div class="col-md-12">
            <ol class="breadcrumb">
                <li><a href="{% url 'dcim:devicetype_list' %}">Device Types</a></li>
                <li><a href="{% url 'dcim:devicetype_list' %}?manufacturer={{ object.manufacturer.slug }}">{{ object.manufacturer }}</a></li>
                <li>{{ object.model }}</li>
            </ol>
        </div>
    </div>
    <div class="pull-right noprint">
        {% plugin_buttons object %}
        {% if perms.dcim.change_devicetype %}
            <div class="btn-group">
                <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add Components <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    {% if perms.dcim.add_consoleporttemplate %}
                        <li><a href="{% url 'dcim:consoleporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_consoleports">Console Ports</a></li>
                    {% endif %}
                    {% if perms.dcim.add_consoleserverporttemplate %}
                        <li><a href="{% url 'dcim:consoleserverporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_consoleserverports">Console Server Ports</a></li>
                    {% endif %}
                    {% if perms.dcim.add_powerporttemplate %}
                        <li><a href="{% url 'dcim:powerporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_powerports">Power Ports</a></li>
                    {% endif %}
                    {% if perms.dcim.add_poweroutlettemplate %}
                        <li><a href="{% url 'dcim:poweroutlettemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_poweroutlets">Power Outlets</a></li>
                    {% endif %}
                    {% if perms.dcim.add_interfacetemplate %}
                        <li><a href="{% url 'dcim:interfacetemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_interfaces">Interfaces</a></li>
                    {% endif %}
                    {% if perms.dcim.add_frontporttemplate %}
                        <li><a href="{% url 'dcim:frontporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_frontports">Front Ports</a></li>
                    {% endif %}
                    {% if perms.dcim.add_rearporttemplate %}
                        <li><a href="{% url 'dcim:rearporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_rearports">Rear Ports</a></li>
                    {% endif %}
                    {% if perms.dcim.add_devicebaytemplate %}
                        <li><a href="{% url 'dcim:devicebaytemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_devicebays">Device Bays</a></li>
                    {% endif %}
                </ul>
            </div>
        {% endif %}
        {% if perms.dcim.add_devicetype %}
            {% clone_button object %}
        {% endif %}
        {% if perms.dcim.change_devicetype %}
            {% edit_button object use_pk=True %}
        {% endif %}
        {% if perms.dcim.delete_devicetype %}
            {% delete_button object use_pk=True %}
        {% endif %}
    </div>
    <h1>{{ object.manufacturer }} {{ object.model }}</h1>
    {% include 'inc/created_updated.html' %}
    <div class="pull-right noprint">
        {% custom_links object %}
    </div>
    <ul class="nav nav-tabs">
        <li role="presentation"{% if not active_tab %} class="active"{% endif %}>
            <a href="{{ object.get_absolute_url }}">Device Type</a>
        </li>
        {% if perms.extras.view_objectchange %}
            <li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
                <a href="{% url 'dcim:devicetype_changelog' pk=object.pk %}">Change Log</a>
            </li>
        {% endif %}
    </ul>
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col-md-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <strong>Chassis</strong>
                </div>
                <table class="table table-hover panel-body attr-table">
                    <tr>
                        <td>Manufacturer</td>
                        <td><a href="{% url 'dcim:devicetype_list' %}?manufacturer={{ object.manufacturer.slug }}">{{ object.manufacturer }}</a></td>
                    </tr>
                    <tr>
                        <td>Model Name</td>
                        <td>
                            {{ object.model }}<br/>
                            <small class="text-muted">{{ object.slug }}</small>
                        </td>
                    </tr>
                    <tr>
                        <td>Part Number</td>
                        <td>{{ object.part_number|placeholder }}</td>
                    </tr>
                    <tr>
                        <td>Height (U)</td>
                        <td>{{ object.u_height }}</td>
                    </tr>
                    <tr>
                        <td>Full Depth</td>
                        <td>
                            {% if object.is_full_depth %}
                                <i class="mdi mdi-check-bold text-success" title="Yes"></i>
                            {% else %}
                                <i class="mdi mdi-close-thick text-danger" title="No"></i>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Parent/Child</td>
                        <td>
                            {{ object.get_subdevice_role_display|placeholder }}
                        </td>
                    </tr>
                    <tr>
                        <td>Front Image</td>
                        <td>
                            {% if object.front_image %}
                                <a href="{{ object.front_image.url }}">
                                    <img src="{{ object.front_image.url }}" alt="{{ object.front_image.name }}" class="img-responsive" />
                                </a>
                            {% else %}
                                <span class="text-muted">&mdash;</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Rear Image</td>
                        <td>
                            {% if object.rear_image %}
                                <a href="{{ object.rear_image.url }}">
                                    <img src="{{ object.rear_image.url }}" alt="{{ object.rear_image.name }}" class="img-responsive" />
                                </a>
                            {% else %}
                                <span class="text-muted">&mdash;</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Instances</td>
                        <td><a href="{% url 'dcim:device_list' %}?device_type_id={{ object.pk }}">{{ instance_count }}</a></td>
                    </tr>
                </table>
            </div>
            {% plugin_left_page object %}
        </div>
        <div class="col-md-6">
            {% include 'inc/custom_fields_panel.html' %}
            {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='dcim:devicetype_list' %}
            <div class="panel panel-default">
                <div class="panel-heading">
                    <strong>Comments</strong>
                </div>
                <div class="panel-body rendered-markdown">
                    {% if object.comments %}
                        {{ object.comments|render_markdown }}
                    {% else %}
                        <span class="text-muted">None</span>
                    {% endif %}
                </div>
            </div>
            {% plugin_right_page object %}
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            {% plugin_full_width_page object %}
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active">
                    <a href="#interfaces" role="tab" data-toggle="tab">Interfaces {% badge interface_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#frontports" role="tab" data-toggle="tab">Front Ports {% badge front_port_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#rearports" role="tab" data-toggle="tab">Rear Ports {% badge rear_port_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#consoleports" role="tab" data-toggle="tab">Console Ports {% badge consoleport_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#consoleserverports" role="tab" data-toggle="tab">Console Server Ports {% badge consoleserverport_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#powerports" role="tab" data-toggle="tab">Power Ports {% badge powerport_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#poweroutlets" role="tab" data-toggle="tab">Power Outlets {% badge poweroutlet_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#devicebays" role="tab" data-toggle="tab">Device Bays {% badge devicebay_table.rows|length %}</a>
                </li>
            </ul>
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="interfaces">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=interface_table title='Interfaces' tab='interfaces' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="frontports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=front_port_table title='Front Ports' tab='frontports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="rearports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=rear_port_table title='Rear Ports' tab='rearports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="consoleports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=consoleport_table title='Console Ports' tab='consoleports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="consoleserverports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=consoleserverport_table title='Console Server Ports' tab='consoleserverports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="powerports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=powerport_table title='Power Ports' tab='powerports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="poweroutlets">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=poweroutlet_table title='Power Outlets' tab='poweroutlets' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="devicebays">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=devicebay_table title='Device Bays' tab='devicebays' %}
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block javascript %}
<script type="text/javascript">
// Redirect user to appropriate components tab if specified
var hash = document.location.hash;
var prefix = "tab_";
if (hash) {
    $('.nav-tabs a[href="'+hash.replace(prefix,"")+'"]').tab('show');
}
$('.nav-tabs a').on('shown.bs.tab', function (e) {
    window.location.hash = e.target.hash.replace("#", "#" + prefix);
});
</script>
{% endblock %}
